package com.yeyks.commonReference.utils;


import com.yeyks.common.em.ResponseStatus;
import com.yeyks.common.exception.ServiceException;
import com.yeyks.consumer.dal.domain.UserInfo;

/**
 * @author fuchangshuai
 * @date 2019/05/07 11:04
 */
public final class UserUtils {

    private static ThreadLocal<UserInfo> user = new ThreadLocal<>();

    public static void putLoginUser(UserInfo currentUser) {
        user.set(currentUser);
    }

    public static UserInfo getLoginUser() {
        UserInfo userInfo = user.get();
        if (userInfo == null) {
            throw new ServiceException(ResponseStatus.RS_FAIL_INVALID_TOKEN.getCode(), "用户信息失效，请重新登录");
        }
        return userInfo;
    }

}

